<template>
  <div class="app-container">
    <el-form ref="form" :model="form" :rules="rules" label-width="80px" :inline="false">
      <el-form-item label="房产名称">
        <el-input v-model="buyhouse.housename" readonly />
      </el-form-item>
      <el-form-item label="事件类型" prop="eventtype">
        <el-input v-model="form.eventtype" readonly/>
      </el-form-item>
      <el-form-item label="客户名称" prop="userid">
        <el-input v-model="form.expire" readonly/>
      </el-form-item>
      <el-form-item label="说明" prop="demo">
        <el-input type="textarea" v-model="form.demo" placeholder="说明"/>
      </el-form-item>
    </el-form>
    <div style="text-align: right;">
      <el-button type="primary" @click="submitForm">保存</el-button>
    </div>
  </div>
</template>

<script>
import { checkout } from '@/api/house_sale/BuyHouse';

export default {
  name: 'checkout',
  props: ["buyhouse","refresh"],
  data() {
    return {
      form: {
        houseid: null,
        eventtype: null,
        expire: null,
        userid: null,
        demo: null,
        buyid: null
      },
      rules: {

      },
    }
  },
  created() {
    this.init();
  },
  watch: {
    refresh() {
      this.init();
    }
  },
  methods: {
    // 初始化表单数据
    init() {
      this.form.eventtype = '退房';
      this.form.userid = this.$store.state.user.name;
      this.form.expire = this.buyhouse.custname;
      this.form.houseid = this.buyhouse.hourseid;
      this.form.buyid = this.buyhouse.buyid;
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          console.log(this.form);
          checkout(this.form).then(response => {
            this.$modal.msgSuccess("退房成功");
            this.$emit("next");
          });
        }
      });
    },
  }
}
</script>
